<!DOCTYPE html>
<html lang="en">
<head>
    {template 'common/edithead'}
    <!--微擎 -->
    <!--这个放在最后一切平白安全-->
    <script type="text/javascript" src="./resource/js/require.js?v=20170915"></script>
    <script type="text/javascript">
        //编辑器里使用
        var urobj=[];
    </script>
</head>
<body class="nav-md" style="min-width: 800px">
<div>
    <div class="container xc_edit_from" >
        <div class="main_container" style="overflow-x: hidden;min-height: calc(100vh - 20px);background-color: white;width: 100%;">
            <div class="col-md-12 col-xs-12">
                <div class="x_panel">
                    <ul class="we7-page-tab">
                        <li >
                            <a  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">
                                {$xtitleb}- {$xtitlea}列表  </a></li>
                        <li><a a href="{php echo $this->createWebUrl($do, array('op'=>'edit','xtitleb'=>urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}">{$xtitleb}- {$xtitlea}增加</a></li>
                    </ul>
                    <div class="x_content">
                        <br/>
                        <form id="sign-form" class="form-horizontal" role="form" method="post" name="submit">
                            <div class="form-group">
                                <label for="name" class="col-sm-2 control-label">标题</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="name" id="name" value="{$list['name']}">
                                    <input type="hidden" name="id" value="{$list['id']}">
                                    <input type="hidden" name="resources_type" value="3">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分类</label>
                                <div class="col-sm-8">
                                    <select  class="form-control js-select2" name="cid" data-select="{$list['cid']}">
                                        <option value="">请选择分类</option>
                                        {loop $class $index $item}
                                        <option value="{$item['id']}" {if $item['id']==$list['cid']}selected{/if} >{$item['name']}</option>
                                        {/loop}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">封面（750*320）</label>
                                <div class="col-sm-8">
                                    {php echo tpl_form_field_image('bimg',$list['bimg']);}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">链接</label>
                                <div class="col-sm-8">
                                    <div class="input-group ">
                                        <input type="text" class="form-control"  name="link" value="{$list['link']}">
				                        <span class="input-group-btn">
				                            <button class="btn btn-default link" type="button" data-toggle="modal" data-target="#sort_link">选择文章</button>
				                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-8">
                                    <input type="checkbox" class="js-switch" value="1" name="status"
                                           data-value="{$list['status']}" data-field="status">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control"  name="sort" value="{$list['sort']}">
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <input type="button" name="submit" class="btn btn-default" value="提交">
                                    <a type="button" class="btn btn-default"  href="{php echo $this->createWebUrl($do, array('op'=>'list','xtitleb'=> urlencode($xtitleb),'xtitlea'=>urlencode($xtitlea),'new'=>1));}" >返回</a>
                                    <input id="res" name="res" type="reset" style="display:none;" />
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="sort_link"><div class="modal-dialog">
    <style>
        #sort_link .modal-body {padding: 10px 15px;}
        #sort_link .tab-pane {margin-top: 5px; min-height: 400px; max-height: 400px; overflow-y: auto;}
        #sort_tab{margin-bottom: 10px;}
    </style>
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
            <h4 class="modal-title">链接</h4>
        </div>
        <div class="modal-body">
            <iframe width="100%" height="395" frameborder="no" border="0" scrolling="no" allowtransparency="yes" src="{url 'site/entry/banner',array('m'=>$_GPC['m'],'op'=>'article')}"></iframe>
        </div>
        <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" id="sort_close" type="button">关闭</button>
        </div>
        <script>
            var sort_objc='';
            $(function(){
                $(".sort_customize").on('click','.sort_link',function(){
                    var id=$(this).attr("data-id");
                    if(id==2){
                        $("#sort_link").find("#sort_tab li").eq(1).hide();
                    }else{
                        $("#sort_link").find("#sort_tab li").eq(1).show();
                    }
                    sort_objc=this;
                });
                $("#sort_link").find('#sort_tab a').click(function(e) {
                    $('#tab').val($(this).attr('href'));
                    e.preventDefault();
                    $(this).tab('show');
                });
            });
        </script>
    </div>
</div></div>
<div class="modal fade" id="video_test"><div class="modal-dialog">
    <style>
        #sort_link .modal-body {padding: 10px 15px;}
        #sort_link .tab-pane {margin-top: 5px; min-height: 400px; max-height: 400px; overflow-y: auto;}
        #sort_tab{margin-bottom: 10px;}
    </style>
    <div class="modal-content">
        <div class="modal-header">
            <button data-dismiss="modal" class="close" type="button">×</button>
            <h4 class="modal-title">测试观看</h4>
        </div>
        <div class="modal-body">
            <video src="" id="test_link" controls="controls"></video>
        </div>
        <div class="modal-footer">
            <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
        </div>
    </div>
</div></div>
{template 'common/editfoot'}
<script>
	if($("#resources_type1").is(":checked")){
	    $(".resources_type2").hide();
	    $(".resources_type1").show();
	}else if($("#resources_type2").is(":checked")){
	    $(".resources_type1").hide();
	    $(".resources_type2").show();
	}
	
    if($("#type1").is(":checked")){
        $(".type2").hide();
        $(".type3").hide();
        $(".type4").hide();
        $(".type1").show();
    }else if($("#type2").is(":checked")){
        $(".type1").hide();
        $(".type3").hide();
        $(".type4").hide();
        $(".type2").show();
    }else if($("#type3").is(":checked")){
        $(".type1").hide();
        $(".type2").hide();
        $(".type4").hide();
        $(".type3").show();
    }else if($("#type4").is(":checked")){
        $(".type1").hide();
        $(".type2").hide();
        $(".type3").hide();
        $(".type4").show();
    }
    var objc="";
    $(function(){
    	$("input[name='resources_type']").change(function(){
    		if($("#resources_type1").is(":checked")){
    		    $(".resources_type2").hide();
    		    $(".resources_type1").show();
    		}else if($("#resources_type2").is(":checked")){
    		    $(".resources_type1").hide();
    		    $(".resources_type2").show();
    		}
        });
        $("input[name='type']").change(function(){
            if($("#type1").is(":checked")){
                $(".type2").hide();
                $(".type3").hide();
                $(".type4").hide();
                $(".type1").show();
            }else if($("#type2").is(":checked")){
                $(".type1").hide();
                $(".type3").hide();
                $(".type4").hide();
                $(".type2").show();
            }else if($("#type3").is(":checked")){
                $(".type1").hide();
                $(".type2").hide();
                $(".type4").hide();
                $(".type3").show();
            }else if($("#type4").is(":checked")){
                $(".type1").hide();
                $(".type2").hide();
                $(".type3").hide();
                $(".type4").show();
            }
        });
        $("body").on("click",'.link',function(){
            objc=this;
        });
        $("input[name='submit']").click(function(){
            getjson();
            var data=$(".form-horizontal").serialize();
            $.ajax({
                type:"post",
                url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'savemodel','version_id'=>$_GPC['version_id'])}",
                data:data,
                dataType:'json',
                success:function(res){
                    if(res.status==1){
                        if($("input[name='id']").val()==""){
                            $("input[name='res']").click();
                            $("body").find(".img-responsive.img-thumbnail").attr("src","");
                        }
                        swal('操作成功!', '操作成功!', 'success');
                    }else{
                        swal('操作失败!', '操作失败!', 'error');
                    }
                }
            })
        });
        $(".video_test").click(function(){
            var link=$("input[name='link']").val();
            if(link!=""){
                $.ajax({
                    type:"post",
                    url:"{url 'site/entry/'.$_GPC['do'],array('m'=>$_GPC['m'],'op'=>'video_change','version_id'=>$_GPC['version_id'])}",
                    data:{link:link},
                    dataType:'json',
                    success:function(res){
                        if(res.status==1){
                            $("#test_link").attr("src",res.data.link);
                        }else{
                            swal('操作失败!', '操作失败!', 'error');
                        }
                    }
                })
            }
        });
    })
    function getjson(){
        var teacher=[];
        $(".teacher").find("input[name='list']").each(function(){
            var id=$(this).attr("data-id");
            var name=$(this).val();
            if(id!="" && name!=""){
                var data={id:id,name:name};
                teacher.push(data);
            }
        });
        if(teacher.length>0){
            $("input[name='teacher']").val(JSON.stringify(teacher));
        }
    }
</script>
</body>
</html>